import type { CartItem } from '@/types/cart'
import { http } from '@/utils/request'

/**
 *
 * @param skuId SKUID
 * @param count 数量
 */
export const addMemberCartAPI = (skuId: string, count: number) => {
  return http({
    url: '/member/cart',
    method: 'POST',
    data: {
      skuId,
      count
    }
  })
}

/**
 * 获取购物车列表
 */
export const getMemberCartListAPI = () => {
  return http<CartItem[]>({
    url: '/member/cart',
    method: 'GET'
  })
}

/**
 * 删除/清空购物车单品
 * @param data 请求参数
 */
export const deleteMemberCartAPI = (data: { ids: string[] }) => {
  return http({
    url: '/member/cart',
    method: 'DELETE',
    data
  })
}

/**
 * 修改购物车单品
 * @param skuId SKU ID
 * @param data 请求参数
 */
export const modifyMemberCartAPI = (
  skuId: string,
  data?: {
    selected?: boolean
    count?: number
  }
) => {
  return http({
    url: `/member/cart/${skuId}`,
    method: 'PUT',
    data
  })
}

/**
 * 购物车全选/取消全选
 * @param data 请求参数  selected boolean
 */
export const modifyMemberCartAllAPI = (data: { selected: boolean }) => {
  return http({
    url: '/member/cart/selected',
    method: 'PUT',
    data
  })
}
